﻿using IM.Easy.AuthorizationServices.Dtos;
using IM.Easy.Core.OAuth.OAuthUser;
using IM.Easy.Entity.System;
using Mapster;

namespace IM.Easy.AuthorizationServices;

public class UserMapper : IRegister
{
    public void Register(TypeAdapterConfig config)
    {
        //登录用户映射
        config.ForType<SysUser, LoginUser>()
                .Map(dest => dest.Id, src => src.Id)
                .Map(dest => dest.UserName, src => src.UserName)
                .Map(dest => dest.NickName, src => src.NickName)
                .Map(dest => dest.RealName, src => src.RealName)
                .Map(dest => dest.Mobile, src => src.Mobile)
                .Map(dest => dest.Email, src => src.Email)
                .Map(dest => dest.Gender, src => src.Gender)
                .Map(dest => dest.BirthDay, src => src.BirthDay)
                .Map(dest => dest.Avatar, src => src.Avatar);

        //登录信息转登录用户信息
        config.ForType<LoginInput, LoginUser>()
                .Map(dest => dest.UserName, src => src.UserName);


        //oauth 转 第三方账号信息
        config.ForType<UserInfo, ExternalUserAccount>()
            .Map(dest => dest.NickName, src => src.Name)
            .Map(dest => dest.UserName, src => src.Login)
            .Map(dest => dest.ProviderUserId, src => src.Id)
            .Map(dest => dest.Email, src => src.Email)
            .Map(dest => dest.AvatarUrl, src => src.AvatarUrl)
            .Map(dest => dest.Provider, src => src.Provider);


    }
}
